package com.hf.healthy_life.service.ServiceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hf.healthy_life.mapper.TaskMapper;
import com.hf.healthy_life.pojo.HealthTaskInformation;
import com.hf.healthy_life.service.TaskService;
import com.hf.healthy_life.vo.CalculateProgressVo;
import com.hf.healthy_life.vo.WeekFinishVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TaskServiceImpl implements TaskService {
    @Autowired
    private TaskMapper taskMapper;
    /*添加任务*/
    @Override
    public int add(HealthTaskInformation task) {
        return taskMapper.insert( task);
    }

    @Override
    public List<HealthTaskInformation> getAll(Long userId) {
        //查询所有任务，条件为userId=传入的userId
        List<HealthTaskInformation> taskList = taskMapper.selectList(new QueryWrapper<HealthTaskInformation>().eq("user_id", userId));
        return taskList;
    }
    /*修改任务,主要是将任务状态设置为已完成*/
    @Override
    public int update(HealthTaskInformation task) {
        return taskMapper.updateById(task);
    }
    /*删除任务*/
    @Override
    public int delete(Long taskId) {
        return taskMapper.deleteById(taskId);
    }

    @Override
    public CalculateProgressVo calculateProgress(Long userId) {
        CalculateProgressVo calculateProgressVo =   taskMapper.calculateProgress(userId);
        //设置当前日期
        calculateProgressVo.setDate(new Date());
        return calculateProgressVo;
    }
    /*查询本星期任务完成情况*/
    @Override
    public WeekFinishVo getIfFinish(Long userId) {
        //获取当前系统时间
        Date date = new Date();
        WeekFinishVo weekFinishVo = taskMapper.getIfFinish(userId);
        weekFinishVo.setDate(date);

        return weekFinishVo;
    }
    /*获取当前连续打卡天数*/
    @Override
    public int getAchievement(Long userId) {
        return taskMapper.getAchievement(userId);
    }
}
